/**
 * Created by Administrator on 2017/7/18 0018.
 */
//sublist 获取全部订阅新闻判断页面状态
/*
 清除多余数据
 */
$.cookie("eid","");//经验id
$.cookie("qid","");//问题ID
$.cookie("fromuser","");//来源者
$.cookie("totop","");//新闻类别定位
$.cookie("newsimg","");//新闻图片
$.cookie("newsurl","");//新闻网址
$.cookie("thumbsUp","");//新闻点赞
$.cookie("newstitle","");//新闻标题
$.cookie("newstypeid","");//新闻类别
$.cookie("newsShareId","");//新闻分享id
/*
 资讯圈红点关闭
 */
$.cookie("subscribe","loaded");

var hash={};//类别id
var hashname={};//类别名
var hashparentid={};//所属类别
var idgetname={};//新闻id获取新闻名
var idgettype={};//新闻id获取类别
var alchoicenum=0;//记录选择了几个行业
var ajaxing=false;
var currentSIndex=1;//订阅默认为1
var pageSSize=15;//订阅默认为15 返回接口数据错误改20
var currentNIndex=1;//新闻默认为1
var pageNSize=15;//新闻默认为15
var currentLIndex=1;//最新资讯默认为1
var pageLSize=15;//最新资讯默认为15 返回接口数据错误改20
var readyover=1;//默认不可以滚动
var firstNewsTime="";
/*
 //iframe处理图片
 */

//跳转 历史定位
//增加点击数
function addClickNum(nid){
    $.ajax({
        type:"post",
        datatype:"json",
        url:addcounturl,
        data:{"newsId":nid},
        success:function(d){
            savepage();//保存页码 距离
            $.cookie("newstypeid","");
            canclick3=true;//点击三次判断
            newscanclick=true;//防止多次点击
            location.href=goClick3Url;
        }
    });
}
var goClick3Url="";
var testUserId="";
var canclick3=true;//点击三次判断
var newscanclick=true;//防止多次点击
function newsgohref(e){
    if(e.dataset.id&&newscanclick){
        var pcUrl=true;
        var errorUrl=/环球网|1905电影网|中国会计视野|编织人生网|IT之家|优姿美女/;
        if(e.dataset.sitename){
            if(errorUrl.test(e.dataset.sitename)){pcUrl=false;}
        }
        var neid=e.dataset.id;
        var typeid=e.dataset.typeid;
        var shareuserid="";
        if(e.dataset.shareid){
            shareuserid="#newsShareId="+e.dataset.shareid;
        }
        if(e.dataset.enick){
            $("#threeFriendNick").html(e.dataset.enick);
        }else{
            $("#threeFriendNick").html("TA");
        }
        if(pcUrl){goClick3Url="newsdetail.html?newsid="+neid+"#fromuser="+$.cookie("MYID")+shareuserid;}
        else{goClick3Url="http://www.pulu.com/weixin/newsdetail.html?newsid="+neid+"#fromuser="+$.cookie("MYID")+shareuserid;}
        if(e.dataset.euser){
            testUserId=e.dataset.euser;
            if(e.dataset.euser!= $.cookie("MYID")&&canclick3){
                canclick3=false;
                newscanclick=false;
                $.ajax({
                    type:"get",
                    url:click3addFriend+"?userId="+$.cookie("MYID")+"&quserId="+testUserId,
                    datatype:"json",
                    success:function(data){
                        //console.log(data);
                        canclick3=true;
                        newscanclick=true;
                        if(data.Data){$("#threeFriend").css("display","block");}
                        else{addClickNum(neid)}
                    }
                })
            }
            else{addClickNum(neid)}
        }else{
            addClickNum(neid)
        }
    }
}
/*
 点击三次加好友
 */
$("#threeFriOk").click(function(){
    var mynick="";
    if($.cookie("MYNICK")){ mynick=$.cookie("MYNICK");}
    //var nftn=new saveFriendMessage();
    //nftn.addFriend(testUserId,mynick);
    newscanclick=true;//防止多次点击
    conn.subscribe({
        to: testUserId,
        message: mynick+"已经阅读你的pulu3次，请求加为好友"
    });
    //发送好友模板
    $.ajax({
        type:"post",
        url:savefriendnoteurl0,
        data:{"userId": $.cookie("MYID"),"friendId":testUserId,"msg":""},
        success:function(d){
            //关闭三次
            $.ajax({
                type:"post",
                url:closeClick3,
                datatype:"json",
                data:{"userId":$.cookie("MYID"),"quserId":testUserId},
                success:function(data){
                    //console.log(data);
                    $("#threeFriend").css("display","none");
                    location.href=goClick3Url;
                }
            });
        }
    });
});
$("#threeFriNo").click(function(){
    newscanclick=true;//防止多次点击
    $.ajax({
        type:"post",
        url:closeClick3,
        datatype:"json",
        data:{"userId":$.cookie("MYID"),"quserId":testUserId},
        success:function(data){
            //console.log(data);
            $("#threeFriend").css("display","none");
            location.href=goClick3Url;
        }
    });
});
//跳转到新闻列表页面
function gonewstype(e){
    var newstypeid= e.dataset.ntype;
    $.cookie("newstypeid",newstypeid);
    savepage();//保存页码 距离
    if(/Cell/.test(e.className)){
        var navlist=e.dataset.partype;
        location.href="mycountry.html?typeid="+newstypeid+"#returnLoad="+navlist;
    }
    else{
        location.href="mycountry.html?typeid="+newstypeid;
    }
}
//所有新闻类别列表
function getAllNewsTypeList(){
    hash={};//类别id
    hashname={};//类别名
    hashparentid={};//所属类别
    idgetname={};//新闻id获取新闻名
    idgettype={};//新闻id获取类别
    $("#alwayspage .zhlistbox div").remove();
    $("#alwayspage .hylistbox div").remove();
    $("#alwayspage .xqlistbox div").remove();

    $.ajax({
        type:"get",
        url:subscribelisturl+ $.cookie("MYID"),
        success:function(d){
            for(var r=0;r< d.Data.length;r++){
                var pinyinID=pinyin.getFullChars(d.Data[r].name).toLowerCase();
                //保存所有的新闻
                if(!hash[pinyinID]){hash[pinyinID]=d.Data[r].id};
                if(!hashname[pinyinID]){hashname[pinyinID]=d.Data[r].name};
                if(!hashparentid[pinyinID]){hashparentid[pinyinID]=d.Data[r].parentId};
                if(!idgetname[d.Data[r].id]){idgetname[d.Data[r].id]=d.Data[r].name};
                if(!idgettype[d.Data[r].id]){idgettype[d.Data[r].id]=d.Data[r].parentId};
                //加载所有新闻
                if(d.Data[r].ishit){
                    var isSubscribe="<span class='tc_text rt subscribe' id='b"+ d.Data[r].id+"' onclick='alchoicethis(this)'>取消</span>";
                    var isclicked=" isclicked";
                    $(".choicenewsname").css("display","block");
                    $(".origword").css("display","none");
                    $("#choiceThree .choicenewsname").prepend(" <span id='d"+d.Data[r].id+"' data-type='"+d.Data[r].parentId+"'>"+d.Data[r].name+"</span> ");
                    ++alchoicenum;
                }
                else{
                    var isSubscribe="<span class='tc_text rt' id='b"+ d.Data[r].id+"' onclick='alchoicethis(this)'>订阅</span>";
                    var isclicked="";
                }
                //类别
                var listboxname="zhlistbox";
                if(d.Data[r].parentId==190){
                    listboxname="zhlistbox";//综合
                }else if(d.Data[r].parentId==191){
                    listboxname="hylistbox";//行业
                }else if(d.Data[r].parentId==192){
                    listboxname="xqlistbox";//兴趣
                }
                if(d.Data[r].ishit){ //已选择的放在最前面
                    $("#alwayspage ."+listboxname).prepend("<div class='Cell"+isclicked+"' data-ntype='"+d.Data[r].id+"' onclick='gonewstype(this)' data-parType='"+listboxname+"'><div class='tc_image'><img src='hyimg/"+ d.Data[r].id+".png' class='topic_photo_img'></div><span class='tc_inner'  id='"+pinyinID+"'><span class='tc_text'>"+d.Data[r].name+"</span>"+isSubscribe+"<span class='rt look'>查看</span></span><div class='tc_stroke'></div></div>");
                }
                else{
                    $("#alwayspage ."+listboxname).append("<div class='Cell"+isclicked+"' data-ntype='"+d.Data[r].id+"' onclick='gonewstype(this)' data-parType='"+listboxname+"'><div class='tc_image'><img src='hyimg/"+ d.Data[r].id+".png' class='topic_photo_img'></div><span class='tc_inner'  id='"+pinyinID+"'><span class='tc_text'>"+d.Data[r].name+"</span>"+isSubscribe+"<span class='rt look'>查看</span></span><div class='tc_stroke'></div></div>");
                }
            }
        }
    });
}

/*
 保存跳转页码 距离
 */
function savepage(){
    var scrollTop=$(window).scrollTop();
    $.cookie("puluscrollTop",scrollTop);
    if($(".allnewsbox").css("display")==="block"){
        $.cookie("puluShowPage","allnewsbox");
        $.cookie("pulucurrentIndex",currentNIndex);
    }else if($(".alllistbox").css("display")==="block"){
        $.cookie("puluShowPage","alllistbox");
        $.cookie("pulucurrentIndex",currentSIndex);//订阅
    }else if($(".lastbox").css("display")==="block"){
        $.cookie("puluShowPage","lastbox");
        $.cookie("pulucurrentIndex",currentLIndex);////最新资讯
    }
}

/*
 资讯圈评论
 */
function commentnews(i){
    //console.log(i.dataset.shareid);
    savepage();//保存页码 距离
    location.href="comment.html?shareNewsId="+i.dataset.shareid+"&aid=c"+i.dataset.newsid;
}
/*
 资讯圈点赞
 */
var isThumbing=false;
//重复点赞
function repeatUpThumb(){
    $("#collectword").css("display","block");
    setTimeout(function(){
        $("#collectword").css("display","none");
    },1000);
    clearTimeout();
}
function thumbnews(i){
    var newsshareid= i.dataset.shareid;
    if(!isThumbing){ //没有点赞在执行
        if(!/clicked/.test(i.className)){
            isThumbing=true;
            $.ajax({
                type:"post",
                datatype:"json",
                url:"https://www.pulu.com/webapi/api/puluquestion/AddShareNewsUp",//赞
                data:{"shareId":newsshareid,"userId": $.cookie("MYID")},//赞
                success:function(data){
                    //console.log(data);
                    if(data.Message=="成功"||data.Message=="不能重复点赞"){
                        isThumbing=false;
                        i.className="rt thumbNews clicked";
                        $("#shareid"+newsshareid+" .thumbnum").html(parseInt($("#shareid"+newsshareid+" .thumbnum").html())+1);
                        if(data.Message=="不能重复点赞"){repeatUpThumb();}
                    }else{
                        isThumbing=false;
                    }
                }
            })
        }
        else{
            repeatUpThumb();
        }
    }
}
//保存当前切换的类型 用于刷新
function savePageType(){
    if($(".allnewsbox").css("display")==="block"){
        $.cookie("puluShowPage","allnewsbox");
    }else if($(".alllistbox").css("display")==="block"){
        $.cookie("puluShowPage","alllistbox");//订阅
    }else if($(".lastbox").css("display")==="block"){
        $.cookie("puluShowPage","lastbox");//最新资讯
    }
}
//新闻回复评论
function comment(e){
    if($.cookie("MYID")){
        if(e.dataset.uid&&e.dataset.uid!= $.cookie("MYID")){
            savepage();
            var sendeid="";
            var replyname="";
            if(e.dataset.replyuser){
                sendeid="&replyuser="+e.dataset.replyuser;
                replyname="&replyname="+e.dataset.replyname;
            };
            location.href="comment.html?shareNewsId="+e.dataset.shareid+"&aid=c"+e.dataset.id+sendeid+replyname;
        }
    }
};

if($.cookie("MYID")){
    if($.cookie("MYNICK")){
        $("#threeFriend .ModelFormBody span#threeFriendMy").html($.cookie("MYNICK"));
    }
    //发新闻
    $("#sendbtn").click(function(){location.href="sendnews.html"});
    //加载全部订阅
    function subnews(d){
        newscanclick=true;//加载完 新闻可以点击
        //用户转发新闻有自己的评论
        var uview="";
        //时间
        var datatime="";
        if(d.published_date){datatime=getDateDiff(getDateTimeStamp(d.published_date));}
        if(!datatime||datatime=="undefined"){datatime="刚刚"};
        //类型
        var typeneme=d.newsType+"·",sitename=d.siteName+"·";
        if(d.newsTypeId==202){typeneme="";sitename=""};//转发网址 外部

        //系统推荐
        var moretype="";//查看更多
        unick="<i onclick='gonewstype(this)' data-ntype='"+d.newsTypeId+"'>订阅号- <b>"+d.newsType+"</b></i>";
        uimgword="<img class='profile_photo_img' src='hyimg/"+d.newsTypeId+".png' onload='showloadimg(this)' style='display:none;'>";
        typeneme="";
        //新闻有图片
        var newsimgurl="img/puluweixin.jpg";
        if(d.newsImg){newsimgurl=d.newsImg;}
        var imgword="<div class='feed_answer_preview answer_content'><h2 class='no_highlight'><a class='question_link hrefto' onclick='newsgohref(this)' data-sitename='"+d.siteName+"' data-id='"+d.qid+"' data-typeid='"+d.newsTypeId+"'><span class='question_text'><span class='rendered_qtext'>"+d.title+"</span></span></a></h2><a onclick='newsgohref(this)' data-sitename='"+d.siteName+"' data-id='"+d.qid+"' data-typeid='"+d.newsTypeId+"'><div class='truncated_newsImgnail_holder'><span class='rendered_qtext'><div class='qtext_image_wrapper' style='background:url("+newsimgurl+")no-repeat center;background-size:cover;'><canvas class='qtext_image_placeholder landscape qtext_image zoomable_in_feed' width='500' height='500' style='visibility: hidden;'></canvas></div></span></div></a></div>";

        $("#alwayspage .alllistbox .body").append("<div class='pagedlist_item'> <div class='feed_item feed_type_answer'>"+"<div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='photo_wrapper'> <div class='photo'> "+ uimgword+" </div> </div> <div class='info_wrapper'> <span class='sign rt' onclick='gonewstype(this)' data-ntype='"+d.newsTypeId+"'>"+moretype+"</span><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span> </span><div class='ContentFooter' data-ntype='"+d.newsTypeId+"'><b>"+typeneme+"</b>"+sitename+datatime+"</div></div> </div> </div> "+uview+"<div class='Answer'><div class='QuestionAnswerVerbose SimpleToggle Toggle'>"+imgword+"</div></div></div></div>");

        //$("#alwayspage .alllistbox .body").append("" +
        //"<div class='pagedlist_item'> " +
        //    "<div class='feed_item feed_type_answer'>"+
        //        "<div class='ContentHeader'> " +
        //            "<div>" +
        //                "<div class='rt' style='color:#09f;font-size:13px;'>查看TA的资料</div>" +
        //                "<div>" +
        //                    "<span style='color:#333;font-size:15px;margin-right:10px;'>匿名</span>" +
        //                    "<span style='color:#999;font-size:13px;'>"+datatime+"</span>" +
        //                "</div>"+
        //            "</div>"+
        //        "</div> "+uview+
        //        "<div class='Answer'>" +
        //            "<div class='QuestionAnswerVerbose SimpleToggle Toggle'>"+imgword+"</div>" +
        //        "</div>" +
        //    "</div>" +
        //"</div>");
    };
    //获取所有订阅新闻
    function sublist(cIndex,pSize){
        $.ajax({
            type:"get",
            url:getUserSubUrl+$.cookie("MYID")+"&currentIndex="+cIndex+"&pageSize="+pSize+"&date="+firstNewsTime,
            complete:function(XHR, TS){
                if(XHR.status==0){
                    window.location.reload();
                }
            },
            success:function(data){
                if(data.Message=="没有数据"||!data.Data||data.Data.length==0){
                    readyover=1;
                    $("#waiting1").css("display","none");
                    $("#nonews1").css("display","block");
                    $("#nonews").css("display","none");
                }else{
                    if(data.Data.length<pSize){
                        $("#waiting1").css("display","none");
                        $("#nonews1").css("display","block");
                        $("#nonews").css("display","none");
                    }
                    if(cIndex==1){
                        firstNewsTime=data.Data[0].published_date;
                    }
                    for(var i=0;i< data.Data.length;i++){
                        //加载新闻
                        subnews(data.Data[i]);
                    }
                    //页面定位
                    if($.cookie("puluShowPage")=="alllistbox"){
                        if(/^[0-9]+$/.test($.cookie("puluscrollTop"))){
                            var toTop= parseInt($.cookie("puluscrollTop"));
                            $(window).scrollTop(toTop);
                            //还原参数
                            pageSSize=15;
                            currentSIndex=parseInt($.cookie("pulucurrentIndex"));
                            //清除定位参数
                            //$.cookie("puluShowPage","");//当前页面不清除
                            $.cookie("puluscrollTop","");
                            $.cookie("pulucurrentIndex","");
                        }
                    }
                    readyover=0;
                }
            }
        });
    }
    //加载最新新闻
    function lastnews(data){
        newscanclick=true;//加载完 新闻可以点击
        //截取时间
        var tim="";
        if(data.published_date){
            tim=getDateDiff(getDateTimeStamp(data.published_date));
        };
        if(!tim){tim="刚刚"};
        var allhtmlword="";
        if(data.thumb){
            allhtmlword+="<div class='newsbox'  id='"+data.id+"'><div class='tpl-2' onclick='newsgohref(this)' data-sitename='"+data.sitename+"' data-id='"+data.id+"'><a><div class='clr'><div class='info-content rt'><div class='text-content' ><h2><p>"+data.title+"</p></h2></div><div class='news-from'><span class='src-net'>"+data.sitename+"·"+tim+"</span></div></div><div class='pic-content' style='background:url("+data.thumb+")no-repeat center;background-size:cover;'></div></div></a></div></div>";
        }else if(!data.thumb){
            allhtmlword+="<div class='newsbox'  id='"+data.id+"'><div class='tpl-3' data-id='"+data.id+"' onclick='newsgohref(this)' data-sitename='"+data.sitename+"'><a><div class='text-content'><h2><p>"+data.title+"</p></h2></div><div class='news-from'><span class='src-net'>"+data.sitename+"·"+tim+"</span></div></a></div></div>";
        }
        $("#alwayspage .lastbox .body").append(allhtmlword);
    }
    //获取最新新闻
    function lastlist(cIndex,pSize){
        $.ajax({
            type:"get",
            url:lastInformation+$.cookie("MYID")+"&currentIndex="+cIndex+"&pageSize="+pSize,
            success:function(data){
                if(data.Message=="没有数据"||!data.Data||data.Data.length==0){
                    readyover=1;
                    $("#waiting2").css("display","none");
                    $("#nonews2").css("display","block");
                    $("#nonews2").css("display","none");
                }else{
                    if(data.Data.length<pSize){
                        $("#waiting2").css("display","none");
                        $("#nonews2").css("display","block");
                        $("#nonews2").css("display","none");
                    }
                    for(var i=0;i< data.Data.length;i++){
                        //加载新闻
                        lastnews(data.Data[i]);
                    }
                    //页面定位
                    if($.cookie("puluShowPage")=="lastbox"){
                        if(/^[0-9]+$/.test($.cookie("puluscrollTop"))){
                            var toTop= parseInt($.cookie("puluscrollTop"));
                            $(window).scrollTop(toTop);
                            //还原参数
                            pageLSize=15;
                            currentLIndex=parseInt($.cookie("pulucurrentIndex"));
                            //清除定位参数
                            //$.cookie("puluShowPage","");//当前页面不清除
                            $.cookie("puluscrollTop","");
                            $.cookie("pulucurrentIndex","");
                        }
                    }
                    readyover=0;
                }
            }
        });
    }
    //加载资讯圈
    function allnews(d){
        //用户有头像
        var uimgword="";
        if(d.shareUserAva){
            uimgword="<img onclick='usergohref(this)' data-uid='"+d.shareUserId+"' class='profile_photo_img' src='http://42.62.66.198:8003/"+d.shareUserAva+"' onload='showloadimg(this)' style='display:none;'>";
        }else{
            uimgword="<img onclick='usergohref(this)' data-uid='"+d.shareUserId+"' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'>";}
        // 用户有昵称
        var unick="";
        if((d.shareUserNick&&d.shareUserNick.length>0)||d.typeid==202){
            var xttj="",realName="";
            if(d.shareRealName){realName=" ("+d.shareRealName+")"};
            if(d.isstanger==1){xttj="系统推荐 ";realName=""};
            unick="<i>"+xttj+"<i class='usernick' onclick='usergohref(this)' data-uid='"+d.shareUserId+"'>"+d.shareUserNick+realName+"</i></i>";
        }
        //用户转发新闻有自己的评论
        var uview="";
        var desword="自动转发";
        var desReg=new RegExp(desword);
        if(d.des&&!desReg.test(d.des)){
            var newcontentcode=codetoface(d.des);//文字中插入表情图片
            uview="<div class='info_wrapper senderview'><div class='info'><span class='feed_item_answer_user'>"+newcontentcode+"</span></div></div>";
        }
        //if(desReg.test(d.des)){console.log(d.title);}
        //时间
        var datatime="";
        if(d.shareTime){datatime=getDateDiff(getDateTimeStamp(d.shareTime));}
        if(!datatime||datatime=="undefined"){datatime="刚刚"};
        //点击跳转
        var clickftn="onclick='gonewstype(this)'";
        //类型
        var typeneme=d.newsType+"·",sitename=d.siteName+"·";
        if(d.newsTypeId==202){typeneme="";sitename="";clickftn=""};//转发网址 外部
        if(d.istopnews==1){datatime="";sitename=d.siteName};//系统推荐 没有时间
        //系统推荐
        var moretype="";//查看更多
        if(d.istopnews===1){
            var randnum=Math.round(Math.random()*100);
            unick="<i onclick='gonewstype(this)' data-ntype='"+d.newsTypeId+"'>订阅号- <b>"+d.newsType+"</b></i>";
            uimgword="<img class='profile_photo_img' src='hyimg/"+d.newsTypeId+".png' onload='showloadimg(this)' style='display:none;'>";
            moretype="查看更多"+ d.newsType+"资讯("+randnum+")";
            typeneme="";
        }
        //自己的经验可以删除
        var delbtn="";

        //新闻有图片
        var newsimgurl="img/puluweixin.jpg";
        if(d.newsImg){newsimgurl=d.newsImg;}
        var imgword="<div class='feed_answer_preview answer_content'><h2 class='no_highlight'><a class='question_link hrefto' onclick='newsgohref(this)' data-sitename='"+d.siteName+"' data-id='"+d.qid+"' data-typeid='"+d.newsTypeId+"' data-shareid='"+d.shareId+"' data-euser='"+d.shareUserId+"' data-enick='"+d.shareUserNick+"'><span class='question_text'><span class='rendered_qtext'>"+d.title+"</span></span></a></h2><a onclick='newsgohref(this)' data-sitename='"+d.siteName+"' data-id='"+d.qid+"' data-typeid='"+d.newsTypeId+"' data-shareid='"+d.shareId+"' data-euser='"+d.shareUserId+"' data-enick='"+d.shareUserNick+"'><div class='truncated_newsImgnail_holder'><span class='rendered_qtext'><div class='qtext_image_wrapper' style='background:url("+newsimgurl+")no-repeat center;background-size:cover;'><canvas class='qtext_image_placeholder landscape qtext_image zoomable_in_feed' width='500' height='500' style='visibility: hidden;'></canvas></div></span></div></a></div>";
        //新闻有评论
        //新闻是否有评论  是否有点赞
        var haveheartname= "<span class='thumbnum'>"+d.upCount+"</span> 赞";//是否点赞过 修改名称
        var secondword="";
        if(d.answers&&d.answers.length>0){

            for(var r1=0;r1<d.answers.length;r1++){
                var replyto="";
                if(d.answers[r1].toUserName){
                    replyto=" <b>回复</b> "+d.answers[r1].toUserName;
                }
                var secondfaceword=codetoface(d.answers[r1].answerContent);
                secondword+="<div id='second"+d.answers[r1].questionId+"' data-replyname='"+d.answers[r1].userName+"' data-replyuser='"+d.answers[r1].answerUserId+"' data-shareid='"+d.shareId+"' data-uid='"+d.answers[r1].answerUserId+"' data-id='"+d.answers[r1].questionId+"' onclick='comment(this)'><span class='username'>"+d.answers[r1].userName+replyto+"：</span><span class='userword commentbtn'>"+secondfaceword+"</span></div>";
            }
            secondword="<div class='common-iconfont zan-person js_zan'><div class='up-thumb' style='display:none;'><i></i><div class='text'></div></div><div class='chatplace'><i></i><div class='secondword'>"+secondword+"</div></div></div>";
        }
        //点赞
        var hasUN="";//新闻已经点过赞
        if(d.hasUpNews===1){
            hasUN=" clicked";
        }
        var thumbCode="<div class='rt thumbNews"+hasUN+"' data-shareid='"+d.shareId+"' onclick='thumbnews(this)'>赞</div>";
        //加载数据
        //$("#alwayspage .allnewsbox .body").append("<div class='pagedlist_item' id='mainp"+d.shareId+"'> <div class='feed_item feed_type_answer'>"+"<div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='photo_wrapper'> <div class='photo'> "+ uimgword+" </div> </div> <div class='info_wrapper'>"+delbtn+"<span class='sign rt' onclick='gonewstype(this)' data-ntype='"+d.newsTypeId+"'>"+moretype+"</span><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span> </span><div class='ContentFooter'><b "+clickftn+" data-ntype='"+d.newsTypeId+"'>"+typeneme+"</b>"+sitename+datatime+"</div></div> </div> </div> "+uview+"<div class='Answer'><div class='QuestionAnswerVerbose SimpleToggle Toggle'>"+imgword+"<div class='ActionBar'><div class='action_bar_inner' >"+"<div class='actionlist' id='actionlist"+d.shareId+"'><div class='rt commentNews' data-shareid="+d.shareId+" data-newsid="+d.qid+" onclick='commentnews(this)'>评论</div>"+thumbCode+"<div id='shareid"+d.shareId+"' data-shareid='"+d.shareId+"' class='addnewscom'>"+d.count+" 浏览 · "+haveheartname+" · "+ d.webchatCount+" 转发到微信</div>"+"</div></div>"+secondword+"</div></div></div></div></div>");

        var levelName="来自同层";
        if(d.manageflag==3||d.techflag==3){levelName="来自高层";}
        if(d.shareUserId== $.cookie("MYID")&& d.istopnews==0){
            delbtn='<div class="delnews rt" onclick="delmynewsftn(this)" data-shareid="'+d.shareId+'">×</div>';
            levelName="来自自己";
        }
        $("#alwayspage .allnewsbox .body").append(
            "<div class='pagedlist_item' id='mainp"+d.shareId+"'> " +
                "<div class='feed_item feed_type_answer'>" +
                    "<div class='ContentHeader' style='min-height:inherit;'>" +
                        "<div>" +
            delbtn+
                            "<div>" +

                                "<div style='color:#09f;font-size:13px;'>" +
                                    "<span onclick='usergohref(this)' data-uid='"+d.shareUserId+"'>"+levelName+"</span>" +
                                    "<span style='color:#999;font-size:13px;margin-left:10px;'>"+datatime+"</span>" +
                                "</div>" +
                            "</div>" +
                        "</div>" +
                    "</div> "+uview+"<div class='Answer'><div class='QuestionAnswerVerbose SimpleToggle Toggle'>"+imgword+"<div class='ActionBar'><div class='action_bar_inner' >"+"<div class='actionlist' id='actionlist"+d.shareId+"'><div class='rt commentNews' data-shareid="+d.shareId+" data-newsid="+d.qid+" onclick='commentnews(this)'>评论</div>"+thumbCode+"<div id='shareid"+d.shareId+"' data-shareid='"+d.shareId+"' class='addnewscom'>"+d.count+" 浏览 · "+haveheartname+" · "+ d.webchatCount+" 转发到微信</div>"+"</div></div>"+secondword+"</div></div></div></div></div>");
    };
    //获取资讯圈
    function newslist(cIndex,pSize){
        $.ajax({
            type:"get",
            url:puluAllNewsUrl+$.cookie("MYID")+"&currentIndex="+cIndex+"&pageSize="+pSize,
            success:function(data){
                if(data.Message=="没有数据"||!data.Data||data.Data.length==0){
                    readyover=1;
                    $("#waiting").css("display","none");
                    $("#nonews").css("display","block");
                }else{
                    if(data.Data.length<pSize){
                        $("#waiting").css("display","none");
                        $("#nonews").css("display","block");
                    }
                    for(var i=0;i< data.Data.length;i++){
                        //加载新闻
                        allnews(data.Data[i]);
                    }
                    //页面定位
                    if($.cookie("puluShowPage")=="allnewsbox"){
                        if(/^[0-9]+$/.test($.cookie("puluscrollTop"))){
                            var toTop= parseInt($.cookie("puluscrollTop"));
                            $(window).scrollTop(toTop);
                            //还原参数
                            pageNSize=15;
                            currentNIndex=parseInt($.cookie("pulucurrentIndex"));
                            //清除定位参数
                            //$.cookie("puluShowPage","");//当前页面不清除
                            $.cookie("puluscrollTop","");
                            $.cookie("pulucurrentIndex","");
                        }
                    }
                    readyover=0;
                }
            }
        });
    }
    //删除转发的新闻操作
    var shareid="";
    function delmynewsftn(e){
        shareid= e.dataset.shareid;
        $("#delmynews").css("display","block");
        $("body").attr("class","overflow");
    }
    $("#delmynewsok").click(function(){
        $("#mainp"+shareid).remove();
        $.ajax({
            type:"post",
            data:{"shareId":shareid},
            url:delmynewsurl,
            success:function(d){
                $("#delmynews").css("display","none");
                $("body").attr("class","");
            }
        })
    });
    $("#delmynewscancel").click(function(){
        shareid="";
        $("#delmynews").css("display","none");
        $("body").attr("class","");
    });
    //加载相关新闻
    if($.cookie("puluShowPage")&&$.cookie("puluShowPage")!="undefined"){
        $("nav a").attr("class","");
        $("#alwayspage .listplace").css("display","none");
        readyover=1;
        $(window).scrollTop(0);
        //清空三个页面 参数还原
        $("#alwayspage .alllistbox").css("display","none");
        $("#alwayspage .alllistbox .body div").remove();//清空页面
        $("#alwayspage .lastbox").css("display","none");
        $("#alwayspage .lastbox .body div").remove();//清空页面
        $("#alwayspage .allnewsbox").css("display","none");
        $("#alwayspage .allnewsbox .body div").remove();//清空页面
        currentSIndex=1;pageSSize=15;//订阅
        currentNIndex=1;pageNSize=15;//新闻
        currentLIndex=1;pageLSize=15;//最新资讯
        //判断保存的页面参数是否正确
        var thisshowpage=$.cookie("puluShowPage");
        if(/allnewsbox|alllistbox|lastbox/.test(thisshowpage)){
            //console.log(thisshowpage);
            //展示保存的页面
            $("#alwayspage ."+thisshowpage).css("display","block");
            $("#"+thisshowpage).attr("class","active");
            //订阅切换栏单独显示
            if(/alllistbox/.test(thisshowpage)){
                $(".tishiword").css("display","block");
            }
            //判断是否有返回定位
            if($.cookie("pulucurrentIndex")&&/[0-9]/.test($.cookie("pulucurrentIndex"))){
                //全部新闻
                if($.cookie("puluShowPage")=="allnewsbox"){


                    if(/^[0-9]+$/.test($.cookie("puluscrollTop"))){
                        pageNSize=parseFloat($.cookie("pulucurrentIndex"))*pageNSize;
                        currentNIndex=1;//一页加载全部
                    }else{
                        pageNSize=15;
                        currentNIndex=1;
                    }
                    sublist(currentSIndex,pageSSize); //第一次执行
                    newslist(currentNIndex,pageNSize);
                    lastlist(currentLIndex,pageLSize);
                }
                //订阅新闻
                else if($.cookie("puluShowPage")=="alllistbox"){

                    $(".tishiword").css("display","block");

                    if(/^[0-9]+$/.test($.cookie("puluscrollTop"))){
                        pageSSize=parseFloat($.cookie("pulucurrentIndex"))*pageSSize;
                        currentSIndex=1;//一页加载全部
                    }else{
                        pageSSize=15;
                        currentSIndex=1;
                    }
                    sublist(currentSIndex,pageSSize);
                    newslist(currentNIndex,pageNSize);
                    lastlist(currentLIndex,pageLSize);
                }
                //最新资讯
                else if($.cookie("puluShowPage")=="lastbox"){

                    if(/^[0-9]+$/.test($.cookie("puluscrollTop"))){
                        pageLSize=parseFloat($.cookie("pulucurrentIndex"))*pageLSize;
                        currentLIndex=1;//一页加载全部
                    }else{
                        pageLSize=15;
                        currentLIndex=1;
                    }
                    sublist(currentSIndex,pageSSize);
                    newslist(currentNIndex,pageNSize);
                    lastlist(currentLIndex,pageLSize);
                }
            }
            //没有返回定位 或者数据不正确
            else{
                sublist(currentSIndex,pageSSize); //第一次执行
                newslist(currentNIndex,pageNSize); //第一次执行
                lastlist(currentLIndex,pageLSize);
            }
        }
        else{
            //保存的页面参数不正确 执行页面
            $("#alwayspage .allnewsbox").css("display","block");
            $("#allnewsbox").attr("class","active");
            sublist(currentSIndex,pageSSize); //第一次执行
            newslist(currentNIndex,pageNSize); //第一次执行
            lastlist(currentLIndex,pageLSize);
        }
    }
    else{
        sublist(currentSIndex,pageSSize); //第一次执行
        newslist(currentNIndex,pageNSize); //第一次执行
        lastlist(currentLIndex,pageLSize);
    }
    //获取所有列表
    getAllNewsTypeList();
    if($.cookie("comfrom")){
        $(".tishiword div").attr("class","");

        var showlist=$.cookie("comfrom");
        $("nav a").attr("class","");
        $("#alllistbox").attr("class","active");
        $("#"+showlist).attr("class","active");
        $("#alwayspage .listplace").css("display","none");
        $("#alwayspage ."+showlist).css("display","block");
        $(".tishiword").css("display","block");
        $.cookie("comfrom","");
        $(window).scrollTop(0);
    }
    //切换类别新闻
    var allnewsboxST=0,lastboxST=0,alllistboxST=0;
    //页面内部滚动记录
    function savePageScrollTop(){
        if($(".allnewsbox").css("display")=="block"){allnewsboxST=$(window).scrollTop();}
        else if($(".lastbox").css("display")=="block"){lastboxST=$(window).scrollTop();}
        else if($(".alllistbox").css("display")=="block"){alllistboxST=$(window).scrollTop();}
    }
    //页面切换定位
    function goPageScrollTop(){
        if($(".allnewsbox").css("display")=="block"){$(window).scrollTop(allnewsboxST);}
        else if($(".lastbox").css("display")=="block"){$(window).scrollTop(lastboxST);}
        else if($(".alllistbox").css("display")=="block"){$(window).scrollTop(alllistboxST);}
        else if($(".zhlistbox").css("display")=="block"){$(window).scrollTop(0)}
        else if($(".hylistbox").css("display")=="block"){$(window).scrollTop(0)}
        else if($(".xqlistbox").css("display")=="block"){$(window).scrollTop(0)}
    }
    $("nav a").click(function(e){
        savePageScrollTop();
        //$(window).scrollTop(0);
        $("nav a").attr("class","");
        $("#"+e.target.id).attr("class","active");
        $("#alwayspage .listplace").css("display","none");
        $("#alwayspage ."+e.target.id).css("display","block");
        if(/allnewsbox|lastbox/.test(e.target.id)){
            $(".tishiword").css("display","none");

        }else{

            $(".tishiword").css("display","block");
        }
        $(".tishiword div").attr("class","");
        $("#alllistbox2").attr("class","active");
        goPageScrollTop(); //页面切换定位
        savePageType();//保存页面切换的类型 刷新
    });
    //切换类别订阅
    $(".tishiword div").click(function(e){
        $(window).scrollTop(0);
        $(".tishiword div").attr("class","");
        var replaceId=e.target.id.replace(/[0-9]/,"");
        $("#"+e.target.id).attr("class","active");
        $("#alwayspage .listplace").css("display","none");
        $("#alwayspage ."+replaceId).css("display","block");
        goPageScrollTop();//页面切换定位
    });
    //选择常看新闻
    function alchoicethis(e){
        //取消事件冒泡
        var eve=arguments.callee.caller.arguments[0]||event; //若省略此句，下面的e改为event，IE运行可以，但是其他浏览器就不兼容
        if (eve && eve.stopPropagation) {
            // this code is for Mozilla and Opera
            eve.stopPropagation();
        } else if (window.event) {
            // this code is for IE
            window.event.cancelBubble = true;
        }
        if(!ajaxing){
            var thisid= e.id;
            var num=thisid.match(/[0-9]+/)[0];
            if(e.parentNode.parentNode.className=="Cell"){

                ajaxing=true;
                //添加类别
                $.ajax({
                    type:"post",
                    url:addsubscribeurl,
                    data:{"userId": $.cookie("MYID"),"typeid":num},
                    success:function(d){
                        ++alchoicenum;
                        e.parentNode.parentNode.className+=" isclicked";
                        e.innerHTML="取消";
                        e.className="tc_text rt subscribe";
                        $("#alsearchinput").val("");
                        //搜索的列表点击
                        if(/s/.test(thisid)){
                            $("#b"+num)[0].parentNode.parentNode.className+=" isclicked";
                            $("#b"+num)[0].innerHTML="取消";
                            $("#b"+num)[0].className="tc_text rt subscribe";
                            $(".searchlistplace div").remove();
                            $(".listplace").css("display","block");
                            $(".searchlistplace").css("display","none");
                        }
                        $("#choiceThree .choicenewsname").prepend(" <span id='d"+num+"' data-type='"+idgettype[num]+"'>"+idgetname[num]+"</span> ");

                        if(alchoicenum>0){
                            $(".choicenewsname").css("display","block");
                            $(".origword").css("display","none");
                        }else{
                            $(".origword").css("display","block");
                            $(".choicenewsname").css("display","none");
                        };
                        ajaxing=false;
                    }
                })
            }
            else if(e.parentNode.parentNode.className=="Cell isclicked"){
                if(alchoicenum<=1){
                    $("#maxNine").css("display","block");
                    $("#maxNine>.min").css("display","block");
                    setTimeout(function(){
                        $("#maxNine").css("display","none");
                        $("#maxNine>.min").css("display","none");
                        clearTimeout();
                    },1500)
                }
                else{
                    ajaxing=true;
                    //删除类别
                    $.ajax({
                        type:"post",
                        url:delsubscribeurl,
                        data:{"userId":$.cookie("MYID"),"typeid":num},
                        success:function(d){
                            var num=thisid.match(/[0-9]+/)[0];
                            $("#d"+num).remove();
                            --alchoicenum;
                            e.parentNode.parentNode.className="Cell";
                            e.innerHTML="订阅";
                            e.className="tc_text rt";
                            $("#alsearchinput").val("");
                            if(/s/.test(thisid)){
                                var num=thisid.match(/[0-9]+/)[0];
                                $("#b"+num)[0].parentNode.parentNode.className="Cell";
                                $("#b"+num)[0].innerHTML="订阅";
                                $("#b"+num)[0].className="tc_text rt";
                                $(".searchlistplace div").remove();
                                $(".listplace").css("display","block");
                                $(".searchlistplace").css("display","none");
                            }

                            if(alchoicenum>0){
                                $(".choicenewsname").css("display","block");
                                $(".origword").css("display","none");
                            }else{
                                $(".origword").css("display","block");
                                $(".choicenewsname").css("display","none");
                            };
                            ajaxing=false;
                        }
                    })
                }
            }
            //else if(alchoicenum>=9){
            //    $("#maxNine").css("display","block");
            //    $("#maxNine>.max").css("display","block");
            //    setTimeout(function(){
            //        $("#maxNine").css("display","none");
            //        $("#maxNine>.max").css("display","none");
            //        clearTimeout();
            //    },1500)
            //}
        }

    }
    //键盘搜索
    document.onkeydown=function(event){
        var e=event||window.event||arguments.callee.caller.arguments[0];
        if(e&&e.keyCode==13){
            $(".searchlistplace div").remove();
            //搜索新闻
            if($("#alwayspage").css("display")==="block"){
                var word=$("#alsearchinput").val();
                if(!word.match(/(\s)/)&&word.length>0){
                    //var tomaodian=pinyin.getFullChars(word).toLowerCase();
                    //var preg=new RegExp(tomaodian);
                    var preg=new RegExp(word);
                    $(".listplace").css("display","none");
                    $(".searchlistplace").css("display","block");
                    $.each(idgetname,function(i,da){
                        if(preg.test(da)){
                            //console.log(i);//id
                            //console.log(da);//中文
                            var tomaodian=pinyin.getFullChars(da).toLowerCase();
                            //console.log(tomaodian);
                            if(hash[tomaodian]){
                                if(/isclicked/.test($("#b"+hash[tomaodian]).parent().parent().attr("class"))){
                                    var isSubscribe="<span class='tc_text rt subscribe' id='s"+hash[tomaodian]+"' onclick='alchoicethis(this)'>取消</span>";
                                    var isclicked=" isclicked";
                                }else{
                                    var isSubscribe="<span class='tc_text rt' id='s"+hash[tomaodian]+"' onclick='alchoicethis(this)'>订阅</span>";
                                    var isclicked="";
                                }
                                $("#alwayspage .searchlistplace").append("<div class='Cell"+isclicked+"' data-ntype='"+hash[tomaodian]+"' onclick='gonewstype(this)'><div class='tc_image'><img src='hyimg/"+ hash[tomaodian]+".png' class='topic_photo_img'></div><span class='tc_inner'><span class='tc_text'>"+hashname[tomaodian]+"</span>"+isSubscribe+"</span><div class='tc_stroke'></div></div>");

                            }
                        }
                    });

                }
            }
        }
    };
    //搜索常看新闻
    $("#alsearchbtn").click(function(){
        $(".searchlistplace div").remove();
        var word=$("#alsearchinput").val();
        if(!word.match(/(\s)/)&&word.length>0){
            //var tomaodian=pinyin.getFullChars(word).toLowerCase();
            //var preg=new RegExp(tomaodian);
            var preg=new RegExp(word);
            $(".listplace").css("display","none");
            $(".searchlistplace").css("display","block");
            $.each(idgetname,function(i,da){
                if(preg.test(da)){
                    //console.log(i);//id
                    //console.log(da);//中文
                    var tomaodian=pinyin.getFullChars(da).toLowerCase();
                    //console.log(tomaodian);
                    if(hash[tomaodian]){
                        if(/isclicked/.test($("#b"+hash[tomaodian]).parent().parent().attr("class"))){
                            var isSubscribe="<span class='tc_text rt subscribe' id='s"+hash[tomaodian]+"' onclick='alchoicethis(this)'>取消</span>";
                            var isclicked=" isclicked";
                        }else{
                            var isSubscribe="<span class='tc_text rt' id='s"+hash[tomaodian]+"' onclick='alchoicethis(this)'>订阅</span>";
                            var isclicked="";
                        }
                        $("#alwayspage .searchlistplace").append("<div class='Cell"+isclicked+"' data-ntype='"+hash[tomaodian]+"' onclick='gonewstype(this)'><div class='tc_image'><img src='hyimg/"+ hash[tomaodian]+".png' class='topic_photo_img'></div><span class='tc_inner'><span class='tc_text'>"+hashname[tomaodian]+"</span>"+isSubscribe+"</span><div class='tc_stroke'></div></div>");

                    }
                }
            });

        }
    });
    //页面返回到首页
    $("#alwaysgoback").click(function(){
        location.href="pulu.html";//history.go(-1);
    });
    //页面滚动
    $(window).scroll(function(){
        if($(".alllistbox").css("display")=="block"){
            var mainheight=$(".alllistbox").height();
            var windowheight=$(window).height();
            var chajuli=$(window).scrollTop()-$(".alllistbox").offset().top;
            var lastheight=mainheight-50;//极限距离
            if((chajuli+windowheight)>lastheight&&readyover===0){
                if(!/[0-9]+/.test(currentSIndex)){currentSIndex=1}
                else{currentSIndex=parseInt(currentSIndex)}
                ++currentSIndex;
                readyover=1;
                sublist(currentSIndex,pageSSize);
            }
        }
        else if($(".allnewsbox").css("display")=="block"){
            var mainheight=$(".allnewsbox").height();
            var windowheight=$(window).height();
            var chajuli=$(window).scrollTop()-$(".allnewsbox").offset().top;
            var lastheight=mainheight-50;//极限距离
            if((chajuli+windowheight)>lastheight&&readyover===0){
                if(!/[0-9]+/.test(currentNIndex)){currentNIndex=1}
                else{currentNIndex=parseInt(currentNIndex)}
                ++currentNIndex;
                readyover=1;
                newslist(currentNIndex,pageNSize);
            }
        }
        else if($(".lastbox").css("display")=="block"){
            var mainheight=$(".lastbox").height();
            var windowheight=$(window).height();
            var chajuli=$(window).scrollTop()-$(".lastbox").offset().top;
            var lastheight=mainheight-50;//极限距离
            if((chajuli+windowheight)>lastheight&&readyover===0){
                if(!/[0-9]+/.test(currentLIndex)){currentLIndex=1}
                else{currentLIndex=parseInt(currentLIndex)}
                ++currentLIndex;
                readyover=1;
                lastlist(currentLIndex,pageLSize);
            }
        }

    });
}
else{
    if(localStorage.getItem("MYID")){
        $.cookie("MYID",localStorage.getItem("MYID"));
        if(is_weixn()){location.href="http://www.pulu.com/weixin/subscribe.html";}
        else{location.href="https://www.pulu.com/weixin/subscribe.html";}
    }else{
        if(is_weixn()){location.href="http://www.pulu.com/weixin/login.html#subscribe";}
        else{location.href="https://www.pulu.com/weixin/login.html#subscribe";}
    }
}